#include "CarPlayProtocol.h"


static CarPlayProtocolDelegate    gProtocolDelegate;


//===========================================================================================================================
//	CarPlayProtocolSetDelegate
//===========================================================================================================================
void CarPlayProtocolSetDelegate( const CarPlayProtocolDelegate *inDelegate )
{
	gProtocolDelegate = *inDelegate;
}
//the following is export by protocol
void iap2LinkStatus(int status) {
	if(gProtocolDelegate.protocolIAP2LinkStatus_f != NULL){
		gProtocolDelegate.protocolIAP2LinkStatus_f(status);
	}
}

int iap2WriteData(char *buf, int len) {
	if(gProtocolDelegate.protocolIAP2WriteData_f != NULL){
		return gProtocolDelegate.protocolIAP2WriteData_f(buf,len);
	}
	return 0;
}

void carplaySessionStart() {
	if(gProtocolDelegate.protocolCarPlaySessionStart_f != NULL){
		 gProtocolDelegate.protocolCarPlaySessionStart_f();
	}
}

void carplaySessionStop() {
	if(gProtocolDelegate.protocolCarPlaySessionStop_f != NULL){
		 gProtocolDelegate.protocolCarPlaySessionStop_f();
	}
}

int switchUsbModeCB(DongleUsbMode mode) {
	if(gProtocolDelegate.protocolSwitchUsbModeCB_f != NULL){
		 return gProtocolDelegate.protocolSwitchUsbModeCB_f(mode);
	}
	return 0;
}

void appleTimeUpdateCB(long long time) {
	if(gProtocolDelegate.protocolAppleTimeUpdateCB_f != NULL){
		 gProtocolDelegate.protocolAppleTimeUpdateCB_f(time);
	}
}

void appleLanguageUpdateCB(const char *lang) {
	if(gProtocolDelegate.protocolAppleLanguageUpdateCB_f != NULL){
		 gProtocolDelegate.protocolAppleLanguageUpdateCB_f(lang);
	}
}

void appleCallStateUpdateCB(const char *remoteId, const char *displayName,
		int status, int direction, const char *uuid, const char *addrBookId,
		const char *label, int service) {
	if(gProtocolDelegate.protocolAppleCallStateUpdateCB_f != NULL){
		 gProtocolDelegate.protocolAppleCallStateUpdateCB_f(remoteId,displayName,status,
				 direction,uuid,addrBookId,label,service);
	}

}

void appleNowPlayingUpdateCB(const char *mediaItemTitle,
										const char *mediaItemAlbumTitle,
										const char *mediaItemArtist,
										int mediaDuration,int state) {
	if(gProtocolDelegate.protocolAppleNowPlayingUpdateCB != NULL){
		 gProtocolDelegate.protocolAppleNowPlayingUpdateCB(mediaItemTitle,mediaItemAlbumTitle,
				 mediaItemArtist,mediaDuration,state);
	}

}

void NotifyDeviceNameCB(const char *name, int name_len) {
	if(gProtocolDelegate.protocolNotifyDeviceNameCB_f != NULL){
		 gProtocolDelegate.protocolNotifyDeviceNameCB_f(name,name_len);
	}
}

/* *
 * @brief 退出的通知
 * */
void carplayExitCB() {
	if(gProtocolDelegate.protocolCarPlayExitCB_f != NULL){
		 gProtocolDelegate.protocolCarPlayExitCB_f();
	}
}

/* *
 * @brief 点击返回本地界面的按钮通知
 * */
void returnNativeUICB() {
	if(gProtocolDelegate.protocolReturnNativeUICB_f != NULL){
		 gProtocolDelegate.protocolReturnNativeUICB_f();
	}
}

/* *
 * @brief carplay模式改变的通知
 * */
void modesChangeCB(DongleCarPlayModeState *modes) {
	if(gProtocolDelegate.protocolModesChangeCB_f != NULL){
		 gProtocolDelegate.protocolModesChangeCB_f(modes);
	}
}

/* *
 * @brief carplay禁止蓝牙
 * */
void disableBluetoothCB() {
	if(gProtocolDelegate.protocolDisableBluetoothCB_f != NULL){
		 gProtocolDelegate.protocolDisableBluetoothCB_f();
	}
}

/* *
 * @brief 压低其他音频流音量
 * */
void caplayDuckAudioCB(double inDurationSecs, double inVolume) {
	if(gProtocolDelegate.protocolCarPlayDuckAudioCB_f != NULL){
		 gProtocolDelegate.protocolCarPlayDuckAudioCB_f(inDurationSecs,inVolume);
	}
}

/* *
 * @brief 还原其他音频流音量
 * */
void caplayUnduckAudioCB(double inDurationSecs) {
	if(gProtocolDelegate.protocolCarPlayUnduckAudioCB_f != NULL){
		 gProtocolDelegate.protocolCarPlayUnduckAudioCB_f(inDurationSecs);
	}

}

/* *
 * @brief 音频流开始
 * @param 			handle 		该路音频流的操作句柄,要缓存起来,作为playStream/recordStream的第一个参数
 * @param			type  		音频流类型
 * @param 			rate		音频的采样率
 * @param 			bits		音频位宽
 * @param 			channels	音频通道数
 * */
void carplayAudioStartCB(int handle, DongleAudioStreamType type, int rate, int bits,
		int channels) {
	if(gProtocolDelegate.protocolCarPlayAudioStartCB_f != NULL){
		 gProtocolDelegate.protocolCarPlayAudioStartCB_f(handle,type,rate,bits,channels);
	}
}

/* *
 * @brief 音频流停止
 * */
void carplayAudioStopCB(int handle, DongleAudioStreamType type) {
	if(gProtocolDelegate.protocolCarPlayAudioStopCB_f != NULL){
		 gProtocolDelegate.protocolCarPlayAudioStopCB_f(handle,type);
	}
}

/* *
 * @brief 视频流开始
 * */
int carplayVideoStartCB() {
	if(gProtocolDelegate.protocolCarPlayVideoStartCB_f != NULL){
		 gProtocolDelegate.protocolCarPlayVideoStartCB_f();
	}
	return 0;
}

/* *
 * @brief 视频流停止
 * */
void carplayVideoStopCB() {
	if(gProtocolDelegate.protocolCarPlayVideoStopCB_f != NULL){
		 gProtocolDelegate.protocolCarPlayVideoStopCB_f();
	}
}

/* *
 * @brief 视频流数据处理
 * */
int carplayVideoDataProcCB(const char *buf, int len) {
	if(gProtocolDelegate.protocolCarPlayVideoDataProcCB_f != NULL){
		return gProtocolDelegate.protocolCarPlayVideoDataProcCB_f(buf,len);
	}
	return 0;
}

